Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFKD implementation #32

Merged
merged 11 commits into from May 21, 2012
Merged

NFKD implementation #32

merged 11 commits into from May 21, 2012

Conversation

KL-7
Copy link
Contributor

@KL-7 KL-7 commented May 16, 2012

I added NFKD implementation. It ended up being the base class of normalizers hierarchy. I don't like it a bit, as I initially wanted to create some abstract base class for them, but things worked out this way. NFD works absolutely the same way, but skips compatibility decomposition. So it's implemented as a subclass of NFKD with a single overridden method.

During the process I splitted the algorithm into small methods that should make it easier to add NF(K)C algorithms later. Possibly we'll have to revisit the classes hierarchy, but in general it should be quite straightforward (assuming we have composition algorithm implemented) as these forms are build on top of NF(K)D algorithms.

Normalization specs are updated to test both algorithms. I didn't add specific tests for NFKD#normalize. It'd be nice to have some simple test cases for it, but I need some valid normalization examples for that. I remember Andrew generated some of them using JRuby and Java Unicode library. Maybe I'll do the same thing a bit later.

Besides that, I moved code points conversion methods into a separate utility module as in my opinion they are not a responsibility of the normalization classes.

end

def compatibility_decomposition?(mapping)
COMPATIBILITY_FORMATTING_TAG_REGEXP =~ mapping.first
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I misunderstood the purpose of this method, it might be better for it to explicitly return true/false instead of an int/nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's a good practice to return true/false from ?-methods. This one is for internal use so I was less careful about this rule. Give me a couple of minutes, I'll fix it.

@camertron
Copy link
Collaborator

This generally looks absolutely awesome. I just commented on a few lines, but it looks nearly ready to merge in. Let's release a new version of the gem after merging as well.

@KL-7
Copy link
Contributor Author

KL-7 commented May 21, 2012

Hey, @camertron, I turned compatibility_decomposition? into a well-mannered boolean predicate and added a comment with some links to the docs that Andrew and I used for the implementation of normalization algorithms. Is there anything else that you'd like to add/change here?

@camertron
Copy link
Collaborator

Hey @KL-7 yes, looks great. I'll merge it in. I'd like you to add those extra comments at some point, but that's not blocking the merge.

camertron added a commit that referenced this pull request May 21, 2012
Including NFKD implementation.
@camertron camertron merged commit 795a8c3 into twitter:master May 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants